package com.test.slice;

import com.ms.banner.Banner;
import com.ms.banner.BannerConfig;
import com.test.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;

import java.util.List;

import static com.test.MyApplication.*;

public class IndicatorPositionAbilitySlice extends AbilitySlice {
    private Banner banner;
    private ListContainer listContainer;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_indicator_position);
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_style_list);
        banner = (Banner) findComponentById(ResourceTable.Id_banner);
        //简单使用
        banner.setBannerTitles(getDataStr())
                .setPages(getDataInt(), new CustomViewHolder())
                .setAutoPlay(true)
                .setDelayTime(3000)
                .start();

        List<SampleItem> list = getSampleItems(getPositionStr());
        SampleItemProvider sampleItemProvider = new SampleItemProvider(list, this);
        listContainer.setItemProvider(sampleItemProvider);
        listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int position, long l) {
                switch (position) {
                    case 0:
                        banner.setIndicatorGravity(BannerConfig.LEFT);
                        break;
                    case 1:
                        banner.setIndicatorGravity(BannerConfig.CENTER);
                        break;
                    case 2:
                        banner.setIndicatorGravity(BannerConfig.RIGHT);
                        break;
                    default:
                        break;
                }
                banner.start();
            }
        });
    }
}